import Vue from 'vue'
import Router from 'vue-router'
import main from '@/view/main'
import login from '@/view/login'
import home from '@/view/home'

import pddOrder from '@/view/order/pddOrder'
import wmOrder from '@/view/order/wmOrder'
import yzOrder from '@/view/order/yzOrder'
import hzwOrder from '@/view/order/hzwOrder'

import user from '@/view/system/user'
import editUser from '@/view/system/editUser'
import power from '@/view/system/power'
import role from '@/view/system/role'
import sysuser from '@/view/system/sysuser'

import resetPwd from '@/view/system/resetPwd'

import theDocumentary from '@/view/warehouse/theDocumentary/theDocumentary'
import putInStorage from '@/view/warehouse/putInStorage/putInStorage'
import transfers from '@/view/warehouse/transfers/transfers'
import artificial from '@/view/warehouse/artificial/artificial'
import inventory from '@/view/warehouse/inventory/inventory'
import accountsPayable from '@/view/warehouse/accountsPayable/accountsPayable'
import production from '@/view/warehouse/production/production'
import procurementPlan from '@/view/warehouse/procurementPlan/procurementPlan'


import data from '@/view/data/data'
import log from '@/view/data/log'


Vue.use(Router)

const router = new Router({
  mode:'history',
  routes: [
    {
      path: '/login',
      name: 'login',
      component: login
    },{
      path: '/',
      name: '首页',
      redirect: '/home' ,
      component: main,
      children: [
        { path: '/home', component: home, name: '主页' }
      ]
    },{
      path: '/',
      name: '采购计划',
      component: main,
      children: [
        { path: '/procurementPlan', component: procurementPlan, name: '采购计划' }
      ]
    },{
      path: '/',
      name: '采购单',
      component: main,
      children: [
        { path: '/theDocumentary', component: theDocumentary, name: '采购单' }
      ]
    },{
      path: '/',
      name: '入库单',
      component: main,
      children: [
        { path: '/putInStorage', component: putInStorage, name: '入库单' }
      ]
    },{
      path: '/',
      name: '调拨单',
      component: main,
      children: [
        { path: '/transfers', component: transfers, name: '调拨单' }
      ]
    },{
      path: '/',
      name: '人工校正',
      component: main,
      children: [
        { path: '/artificial', component: artificial, name: '人工校正' }
      ]
    },{
      path: '/',
      name: '盘盈盘亏',
      component: main,
      children: [
        { path: '/inventory', component: inventory, name: '盘盈盘亏' }
      ]
    },{
      path: '/',
      name: '应付账款',
      component: main,
      children: [
        { path: '/accountsPayable', component: accountsPayable, name: '应付账款' }
      ]
    },{
      path: '/',
      name: '总仓生产',
      component: main,
      children: [
        { path: '/production', component: production, name: '总仓生产' }
      ]
    }, {
      path: '/',
      name: '用户',
      component: main,
      children: [
        { path: '/resetPwd', component: resetPwd, name: '修改密码' }
      ]
    },{
      path: '/',
      name: '订单列表',
      component: main,
      children: [
        { path: '/pddOrder', component: pddOrder, name: '拼多多订单列表' },
        { path: '/yzOrder', component: yzOrder, name: '有赞订单列表' },
        { path: '/wmOrder', component: wmOrder, name: '微盟订单列表' },
        { path: '/hzwOrder', component: hzwOrder, name: '孩子王订单列表' }
      ]
    },{
      path: '/',
      name: '系统管理',
      component: main,
      children: [
        { path: '/user', component: user, name: '店铺列表' },
        { path: '/editUser', component: editUser, name: '编辑客户信息' },
        { path: '/power', component: power, name: '权限列表' },
        { path: '/role', component: role, name: '角色列表' },
        { path: '/sysuser', component: sysuser, name: '用户列表' }
      ]
    },{
      path: '/',
      name: '数据管理',
      component: main,
      children: [
        { path: '/data', component: data, name: '信息管理' },
        { path: '/log', component: log, name: '日志' }
      ]
    }
  ]
})
router.beforeEach((to,from,next) => {
  //先不做token处理
  // next()
  //做token处理
  if(localStorage.getItem("token") || to.path === "/login"  ){
      next()
  } else{
      next({
          path:'/login',
          query:{redirect: to.fullPath}
      })
  }
})
export default router
